(function () {
    var core = ecui,
        util = core.util,
        ui = core.ui,
        dom = ecui.dom;

    NS.data.tag = '';
    NS.data.good = undefined;
    NS.data.expand = false;
    Object.assign(
        NS.ui,
        {
            TagRadio: ecui.inherits(
                ui.Checkbox,
                {
                    onchange: function () {
                        var value = this.getValue();
                        dom.toArray(document.forms.tagFilterForm.elements.labelId).forEach(function (item) {
                            if (item.value !== value && item.getControl) {
                                item.getControl().setChecked(false);
                            }
                        });
                        NS.data.tag = this.isChecked() ? value : '';
                        if (NS.data.tag === '') {
                            NS.data.good = undefined;
                        } else if (NS.data.tag === '100') {
                            NS.data.good = true;
                        } else if (NS.data.tag === '101') {
                            NS.data.good = false;
                        }
                        // NS.data.good = NS.data.tag !== '' ? undefined : (NS.data.tag === '100' ? true : false);
                        ecui.dispatchEvent(ecui.get('sponsor-comment-list-view'), 'refresh');
                    }
                }
            ),
            Expand: ecui.inherits(
                ui.Checkbox,
                'ui-tag-expand',
                {
                    onchange: function () {
                        NS.data.expand = this.isChecked();
                        var parent = dom.parent(this.getMain()),
                            children = dom.children(parent);
                        children.forEach(function (item, index) {
                            if (index > 2 && index < children.length - 1 && item.getControl) {
                                item.getControl()[this.isChecked() ? 'show' : 'hide']();
                            }
                        }.bind(this));
                    }
                }
            )
        }
    );
    ecui.esr.addRoute('sponsor', {
        model: [
            'detail@GET /erp-management/customer/sponsor/${id}'
        ],
        weight: 3,
        main: 'info_detail-sponsor',
        view: 'detail.sponsor',
        queryUrl: '@JSON /erp-management/data-bank/h5/sponsor/${id}/play-list',
        queryUrl2: '@JSON /erp-management/data-bank/h5/sponsor/${id}/comment-list',
        frame: true,
        CACHE: false,
        children: ['detail.perfDetailList', 'detail.comDetailList'],
        onbeforerequest: function (context) {
        },
        onafterrender: function (context) {
            NS.data.tag = '';
            NS.data.expand = false;
            NS.data.good = undefined;
            ecui.get('sponsor-detail-tab').ontitleclick = function (event) {
                var commentListView = ecui.get('sponsor-comment-list-view');
                if (this.getSelected() !== event.item) {
                    if (event.index === 1) {
                        if (commentListView) {
                            ecui.dispatchEvent(commentListView, 'refresh');
                        }
                    }
                }
            };
        }
    });
    ecui.esr.addRoute('perfDetailList', {
        model: [
            'detail@GET /erp-management/customer/sponsor/${id}'
        ],
        main: 'perfDetailListCont',
        view: 'detail.perfDetailList',
        queryUrl: '@JSON /erp-management/data-bank/h5/sponsor/${id}/play-list',
        CACHE: false,
        onbeforerequest: function (context) {
        },
        onafterrender: function (context) {
            var performListView = ecui.get('sponsor-perform-list-view');
            ecui.dispatchEvent(performListView, 'refresh');

        }
    });
    ecui.esr.addRoute('comDetailList', {
        model: [],
        main: 'comDetailListCont',
        view: 'detail.comDetailList',
        queryUrl: '@FORM /erp-management/data-bank/h5/sponsor/${id}/comment-list?tagFilterForm',
        CACHE: false,
        onbeforerequest: function (context) {
        },
        onafterrender: function (context) {
            // var commentListView =  ecui.get('sponsor-comment-list-view');
            // ecui.dispatchEvent(commentListView, 'refresh');

        }
    });
}());